package kr.saeildamil.androidforstudy2.ch20.common;

import kr.saeildamil.androidforstudy2.R;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class CounterFragment extends Fragment {
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		// Practive01
		/*
		 * View root = inflater.inflate(R.layout.ch20_counterfragment,
		 * container);
		 * 
		 * final TextView textCounter = (TextView)
		 * root.findViewById(R.id.ch20_counterfragment_countertv);
		 * root.findViewById
		 * (R.id.ch20_counterfragment_increasebtn).setOnClickListener(new
		 * OnClickListener() {
		 * 
		 * @Override public void onClick(View v) { int count =
		 * Integer.parseInt(textCounter.getText().toString());
		 * textCounter.setText(Integer.toString(count+1)); } });
		 */

		// Practice02
		/*
		 * LinearLayout root = new LinearLayout(getActivity());
		 * root.setOrientation(LinearLayout.VERTICAL);
		 * root.setBackgroundColor(Color.YELLOW);
		 * root.setGravity(Gravity.CENTER_HORIZONTAL);
		 * 
		 * final TextView textCounter = new TextView(getActivity());
		 * textCounter.setText("0"); textCounter.setTextColor(Color.RED);
		 * textCounter.setTextScaleX(40);
		 * 
		 * Button increaseBtn = new Button(getActivity());
		 * increaseBtn.setText("Increase");
		 * 
		 * LinearLayout.LayoutParams param = new
		 * LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
		 * LinearLayout.LayoutParams.WRAP_CONTENT);
		 * 
		 * root.addView(textCounter, param); root.addView(increaseBtn, param);
		 * 
		 * increaseBtn.setOnClickListener(new Button.OnClickListener() {
		 * 
		 * @Override public void onClick(View v) { int count =
		 * Integer.parseInt(textCounter.getText().toString());
		 * textCounter.setText(Integer.toString(count + 1)); } });
		 */

		// practice03
		/*Button increaseBtm = (Button) getActivity().findViewById(
				R.id.ch20_counterfragment_increasebtn);
		final TextView textCounter = (TextView) getActivity().findViewById(
				R.id.ch20_counterfragment_countertv);

		increaseBtm.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				int count = Integer.parseInt(textCounter.getText().toString());
				textCounter.setText(Integer.toString(count + 1));
			}
		}); */

		View root = inflater.inflate(R.layout.ch20_counterfragment, container);
		
		return root;
		
	} // End of method onCreateView;

	// Practice04
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		Button increaseBtn = (Button) getView().findViewById(
				R.id.ch20_counterfragment_increasebtn);
		final TextView textCounter = (TextView) getView().findViewById(
				R.id.ch20_counterfragment_countertv);

		increaseBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				int count = Integer.parseInt(textCounter.getText().toString());
				textCounter.setText(Integer.toString(count + 1));
			}
		});
	}
	}

	
